package cn.growthgate.fgo.config;

import java.util.Properties;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.google.code.kaptcha.Constants;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;

/**
 * 验证码配置
 * 
 * @author GrowthGate
 * @since 2019年3月30日
 *
 */
@Configuration
public class CaptchaConfig {
	
	@Bean
	public DefaultKaptcha getDefaultKaptcha() {
		DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
		Properties properties = new Properties();

		properties.setProperty(Constants.KAPTCHA_BORDER, "no");
		properties.setProperty(Constants.KAPTCHA_IMAGE_WIDTH, "120");
		properties.setProperty(Constants.KAPTCHA_IMAGE_HEIGHT, "40");
		properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_CHAR_STRING, "3456789ABCDEFGHJKMNPQRSTUVWXY");
		properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "4");
		properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Times New Roman, Arial, Calibri");
		properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_FONT_SIZE, "32");
		properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_FONT_COLOR, "77,77,77");
		properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_CHAR_SPACE, "5");
		properties.setProperty(Constants.KAPTCHA_NOISE_COLOR, "99,99,99");
		properties.setProperty(Constants.KAPTCHA_BACKGROUND_CLR_FROM, "228,228,228");
		properties.setProperty(Constants.KAPTCHA_BACKGROUND_CLR_TO, "248,248,248");

		Config config = new Config(properties);
		defaultKaptcha.setConfig(config);
		return defaultKaptcha;
	}

}
